﻿@inherits LayoutComponentBase
@using FSH.Framework.Blazor.UI.Components.Button
@using FSH.Framework.Blazor.UI.Components.Layouts
@using Microsoft.AspNetCore.Components.Authorization

<MudThemeProvider Theme="@_theme" IsDarkMode="_isDarkMode" />
<MudPopoverProvider />
<MudDialogProvider />
<MudSnackbarProvider />
<AuthorizeView>
    <NotAuthorized>

    </NotAuthorized>
    <Authorized>
    </Authorized>
</AuthorizeView>
<MudLayout>
    <MudAppBar Elevation="0">
        <MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
        <MudSpacer />
        <MudIconButton Icon="@(DarkLightModeButtonIcon)" Color="Color.Inherit" OnClick="@DarkModeToggle" />
        <MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End" />
    </MudAppBar>
    <MudDrawer id="nav-drawer" @bind-Open="_drawerOpen" Elevation="0">
        <MudDrawerHeader>
            <FshDrawerHeader Title="FSH Playground" />
        </MudDrawerHeader>
    </MudDrawer>
    <MudMainContent Class="pt-20 pa-6">
        @Body
    </MudMainContent>
</MudLayout>


<div id="blazor-error-ui" data-nosnippet>
    An unhandled error has occurred.
    <a href="." class="reload">Reload</a>
    <span class="dismiss">🗙</span>
</div>

@code {
    private bool _drawerOpen = true;
    private bool _isDarkMode = false;
    private MudTheme? _theme = null;

    protected override void OnInitialized()
    {
        base.OnInitialized();

        _theme = new()
        {
            PaletteLight = _lightPalette,
            PaletteDark = _darkPalette,
            LayoutProperties = new LayoutProperties(),
            Typography = new Typography()
            {
                Default =
                {
                    FontFamily = new[] { "Inter", "system-ui", "-apple-system", "BlinkMacSystemFont", "\"Segoe UI\"", "sans-serif" },
                    FontSize = "0.95rem",
                    FontWeight = "400",
                    LineHeight = "1.5",
                    LetterSpacing = "0.02em"
                }
            }
        };
    }

    private void DrawerToggle()
    {
        _drawerOpen = !_drawerOpen;
    }

    private void DarkModeToggle()
    {
        _isDarkMode = !_isDarkMode;
    }

    private readonly PaletteLight _lightPalette = new()
    {
        Primary = "#111827",
        Secondary = "#4B5563",
        Surface = "#F9FAFB",
        Background = "#F3F4F6",
        AppbarText = "#111827",
        AppbarBackground = "#F9FAFB",
        DrawerBackground = "#FFFFFF",
        TextPrimary = "#111827",
        TextSecondary = "#4B5563",
        GrayLight = "#E5E7EB",
        GrayLighter = "#F3F4F6",
    };

    private readonly PaletteDark _darkPalette = new()
    {
        Primary = "#6366F1",
        Secondary = "#9CA3AF",
        Surface = "#020617",
        Background = "#020617",
        BackgroundGray = "#020617",
        AppbarText = "#E5E7EB",
        AppbarBackground = "#020617",
        DrawerBackground = "#020617",
        ActionDefault = "#9CA3AF",
        ActionDisabled = "#4B5563",
        ActionDisabledBackground = "#111827",
        TextPrimary = "#F9FAFB",
        TextSecondary = "#9CA3AF",
        TextDisabled = "#4B5563",
        DrawerIcon = "#9CA3AF",
        DrawerText = "#E5E7EB",
        GrayLight = "#1F2937",
        GrayLighter = "#020617",
        Info = "#38BDF8",
        Success = "#22C55E",
        Warning = "#F59E0B",
        Error = "#EF4444",
        LinesDefault = "#111827",
        TableLines = "#111827",
        Divider = "#111827",
        OverlayLight = "#02061780",
    };

    public string DarkLightModeButtonIcon => _isDarkMode switch
    {
        true => Icons.Material.Rounded.AutoMode,
        false => Icons.Material.Outlined.DarkMode,
    };
}


